package com.intellij.licensecommon.data;

import com.intellij.licensecommon.util.LicenseInfo;

import java.util.Date;

public abstract class AbstractSubscriptionLicense extends AbstractSubscriptionLicenseData {
    protected LicenseInfo LicenseInfo = null;
    private static final long f = 1207994548224L;
    private static final long g = 1242108854272L;
    private static final long h = 1271008854016L;

    public AbstractSubscriptionLicense(String key, String username) {
        super(key, username);
    }

    @Override
    public String toString() {
        return getUsername() + ":" + getKey();
    }

    @Override
    public boolean isEvaluationExpired(Date paramDate) {
        if (paramDate == null) {
            return false;
        }
        if (!willExpire()) {
            return false;
        }
        return paramDate.after(this.LicenseInfo.expirationDate);
    }

    @Override
    public boolean isValid() {
        ensureLicenseInfo();
        return hasValidLicenseInfo();
    }

    protected void ensureLicenseInfo() {
        if (hasValidLicenseInfo()) {
            return;
        }
        try {
            this.LicenseInfo = getLicenseInfo();
        } catch (com.intellij.licensecommon.util.a locala) {
            this.LicenseInfo = getDefaultLicenseInfo();
        }
    }

    protected abstract LicenseInfo getLicenseInfo() throws com.intellij.licensecommon.util.a;

    protected LicenseInfo getDefaultLicenseInfo() {
        return LicenseInfo.DEFAULT_LICENSE;
    }

    private boolean hasValidLicenseInfo() {
        return (this.LicenseInfo != null) && (this.LicenseInfo != getDefaultLicenseInfo());
    }

    @Override
    public boolean willExpire() {
        return getExpirationDate() != null;
    }

    @Override
    public Date getExpirationDate() {
        ensureLicenseInfo();
        return this.LicenseInfo.expirationDate;
    }

    @Override
    public boolean isAcademic() {
        ensureLicenseInfo();
        return this.LicenseInfo.licenseId == 1;
    }

    public boolean v() {
        ensureLicenseInfo();
        return this.LicenseInfo.licenseId == 2;
    }

    @Override
    public boolean isOpenSource() {
        ensureLicenseInfo();
        return this.LicenseInfo.licenseId == 3;
    }

    @Override
    public boolean isClassroom() {
        ensureLicenseInfo();
        return this.LicenseInfo.licenseId == 5;
    }

    @Override
    public boolean i() {
        return (!v()) && (!isOpenSource()) && (!isClassroom());
    }

    @Override
    public boolean isPersonal() {
        ensureLicenseInfo();
        return this.LicenseInfo.licenseId == 4;
    }

    @Override
    public Date getGenerationDate() {
        ensureLicenseInfo();
        return this.LicenseInfo.generationDate;
    }

    @Override
    public boolean k() {
        long l = getGenerationDate().getTime();
        return (l == f) || (l == f) || (l == h);
    }

    @Override
    public int getMajorVersion() {
        ensureLicenseInfo();
        return this.LicenseInfo.majorVersion;
    }

    @Override
    public int getLicenseType() {
        ensureLicenseInfo();
        return this.LicenseInfo.productId;
    }
}
